<template>
  <el-dialog :visible.sync="visible"
             title="冲突数据"
             :close-on-click-modal="false"
             :append-to-body="true"
             :before-close="closeDialog"
             class="user-dialog add-or-updata"
             width="45%"
             :close-on-press-escape="false">
    <table-template :tableData='tableData'
                    :loading='dataListLoading'
                    :fieldManagement='false'
                    :index='true'
                    :dataList='dataList'>
      <template slot="createDate-after">
        <el-table-column prop="dealWith"
                         label="处理方式"
                         header-align="center"
                         align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.dealWith === 1">忽略</span>
            <span v-if="scope.row.dealWith === 2">替换</span>
          </template>
        </el-table-column>
      </template>
      <el-table-column :label="$t('handle')"
                       fixed="right"
                       header-align="center"
                       align="center"
                       width="100">
        <template slot-scope="scope">
          <el-button type='text'
                     class='brand'
                     @click='addwin(scope.row.id)'
                     size='small'>详情</el-button>
        </template>
      </el-table-column>
    </table-template>
    <el-pagination :current-page="page"
                   :page-sizes="[10, 20, 50, 100]"
                   :total="total"
                   layout="total, sizes, prev, pager, next"
                   @size-change="pageSizeChangeHandle"
                   @current-change="pageCurrentChangeHandle">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <usererrorList ref="addOrUpdate"
                   @callBack="getDataList" />
  </el-dialog>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import formValidate from '@/mixins/form-validate'
import tableTemplate from '@/components/table-template'
import usererrorList from './user-errorListRecord.vue'
export default {
  mixins: [mixinViewModule, formValidate],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '',
        getDataListIsPage: true,
        deleteURL: '',
        deleteIsBatch: true
      },
      visible: false,
      orderField: '', // 排序，字段
      page: 1, // 当前页码s
      pageSize: 10, // 每页数
      total: 0, // 总条数
      dataListLoading: false, // 数据列表，loading状态
      dataForm: {
        type1: null
      }
    }
  },
  mounted () {
  },
  components: {
    tableTemplate,
    usererrorList
  },
  computed: {
    tableData () {
      return [
        { label: '同步时间', width: '150', prop: 'createDate' },
        { label: '处理人', width: '100', prop: 'userName' }
      ]
    }
  },
  methods: {
    pageSizeChangeHandle (val, fn) {
      this.pageSize = val
      if (fn) {
        fn()
      } else {
        this.getData()
      }
      return Promise.resolve()
    },
    pageCurrentChangeHandle (val, fn) {
      this.page = val
      if (fn) {
        fn()
      } else {
        this.getData()
      }
      return Promise.resolve()
    },
    addwin (_id) {
      if (_id) {
        this.$refs.addOrUpdate.init(_id, this.dataForm.type1)
      } else {
        this.$refs.addOrUpdate.init('', this.dataForm.type1)
      }
    },
    closeDialog () {
      this.dataForm.id = ''
      this.dataForm.type1 = ''
      this.dataForm.name = ''
      this.dataForm.pid = ''
      this.dataForm.parentName = ''
      this.dataForm.prName = ''
      this.dataForm.serialNumber = ''
      this.dataForm.remarks = ''
      this.dataForm.userId = ''
      this.visible = false
      this.$emit('callBack')
    },
    async getData () {
      let paramData = {
        syncType: this.dataForm.type1
      }
      let pageObj = {}
      pageObj.page = this.page
      pageObj.pageSize = this.pageSize
      let obj = {}
      let order = this.order === 'desc' ? 'DESC' : 'ESC'
      if (this.orderField !== '') {
        obj[`OB_${this.orderField}`] = order
      }
      await this.$http.get('system/sysSyncConflictRecord/sqlPage', { params: { ...obj, ...pageObj, ...paramData } }
      ).then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        this.dataList = res.data.data
        this.page = res.data.page
        this.pageSize = res.data.pageSize
        this.total = res.data.total
      })
    },
    init (data) {
      this.dataForm.type1 = data
      this.visible = true
      this.$nextTick(() => {
        this.getData()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
